﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using PBMessage;
using SGLib.Scene;

public class UILobby : BaseWidget
{
    public Text NickName;
    public Text Rank;
    public Text LobbyNumber;

    public override void OnLoad()
    {
        NickName.text = PlayerModel.Instance.Self.NickName;
        Rank.text = PlayerModel.Instance.Self.Rank.ToString();
        LobbyNumber.text = LobbyModel.Instance.LobbyNumber.ToString();

        Game.Inst.Net.SetHandler(PBMesasgeID.SC_LobbyTick, onLobbyTick);
        Game.Inst.Net.SetHandler(PBMesasgeID.SC_EnterGameRoom, onEnterRoomHandler);
    }

    void onLobbyTick(PBPackage pkg)
    {
        LobbyNumber.text = LobbyModel.Instance.LobbyNumber.ToString();
    }

    public void StartMatch()
    {

        CS_StartMatch startMatch = new CS_StartMatch();
        startMatch.MatchType = 0;
        startMatch.UserId = PlayerModel.Instance.Self.GUID;
        Game.Inst.Net.NetClient.Send((int)PBMesasgeID.CS_StartMatch, startMatch);
    }

    public void onEnterRoomHandler(PBPackage pkg)
    {
        UIManager.Inst.Close(this);
        SceneManager.Instance.LoadScene<GameScene>(pkg.Data);
        UIManager.Inst.Show("UISelectUnit");
        
    }
}
